package cn.dfun.demo.scdemo.ali.seata.service.impl;

import cn.dfun.demo.scdemo.ali.seata.dao.AccountDao;
import cn.dfun.demo.scdemo.ali.seata.domain.Account;
import cn.dfun.demo.scdemo.ali.seata.service.AccountService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

@Service
public class AccountServiceImpl implements AccountService {
    @Resource
    private AccountDao accountDao;


    @Override
    public void decrease(Long userId, BigDecimal money) {
        // 模拟超时异常
        try {
            TimeUnit.SECONDS.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        accountDao.decrease(userId, money);
    }
}
